//
//  STProgressView.m
//  OCVVeibo
//
//  Created by leergou on 16/7/21.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

#import "STProgressView.h"


@interface STProgressView ()

/** timer */
@property (nonatomic,strong) NSTimer *timer;

/** isAnimating */
@property (nonatomic,assign) BOOL isAnimating;

@end

@implementation STProgressView

#pragma mark - 重写构造方法
- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame: CGRectMake(0, 20 + 44, SCREEN_WIDTH, 5)]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - valueChanged
- (void)valueChanged{
    
    if (!_isAnimating) {
        self.progress += 0.05;
        if (self.progress >= 0.95) {
            self.progress = 0.95;
        }
    } else {
        if (self.progress == 1) {
            self.hidden = YES;
            [self.timer invalidate];
        } else {
            self.progress += 0.05;
        }
    }
}

#pragma mark - removeProgressView
- (void)removeProgressView{
    [self removeFromSuperview];
}

#pragma mark - endAnimation
- (void)endAnimation{
    self.isAnimating = YES;
}

#pragma mark - startAnimation
- (void)startAnimation{
    self.isAnimating = NO;
    self.progress = 0;
    self.hidden = NO;
    _timer = [NSTimer scheduledTimerWithTimeInterval:1/60 target:self selector:@selector(valueChanged) userInfo:nil repeats:YES];
}

#pragma mark - setupUI
- (void)setupUI{
    self.tintColor = [UIColor greenColor];
}

- (void)dealloc{
    [self.timer invalidate];
}



@end
